{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "a=3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.]]\n"
     ]
    }
   ],
   "source": [
    "w = tf.Variable([[.5,1.0]])\n",
    "x = tf.Variable([[2.0],[1.0]])\n",
    "y = tf.matmul(w,x)\n",
    "\n",
    "init_op = tf.global_variables_initializer()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init_op)\n",
    "    print (y.eval())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "input1 = tf.placeholder(tf.float32)\n",
    "input2 = tf.placeholder(tf.float32)\n",
    "output = tf.multiply(input1,input2)\n",
    "with tf.Session() as sess:\n",
    "    testres = sess.run([output],feed_dict={input1:[7],input2:[2]})\n",
    "    print (len(testres))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'zeros_like_1:0' shape=(2, 3) dtype=int32>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tf.zeros([3,4])\n",
    "tensor = [[1,1,1],[1,1,2]]\n",
    "tf.zeros_like(tensor)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "tensor = tf.constant([1,2,3,3,4,4,5,54434])\n",
    "tensor1 = tf.linspace(-1.0,12.0,3,name='linspacess')\n",
    "# tf.linspace(start, end, num)：这个函数主要的参数就这三个，start代表起始的值，end表示结束的值，num表示在这个区间里生成数字的个数，\n",
    "# 生成的数组是等间隔生成的。start和end这两个数字必须是浮点数，不能是整数，如果是整数会出错的，请注意！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#tf.range(limit, delta=1, dtype=None, name='range')\n",
    "#tf.range(start, limit, delta=1, dtype=None, name='range')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.57890117 -1.43318033 -9.30506039]\n",
      " [ 0.11717069 -3.7756393  -2.20481205]]\n"
     ]
    }
   ],
   "source": [
    "# tf.random_normal用于从服从指定正太分布的数值中取出指定个数的值\n",
    "\n",
    "norm = tf.random_normal([2,3],mean=-1,stddev=4)\n",
    "with tf.Session() as sess:\n",
    "    print(sess.run(norm))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "1\n",
      "2\n",
      "2\n",
      "3\n",
      "3\n",
      "4\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "state = tf.Variable(0)\n",
    "new_value = tf.add(state,tf.constant(1))\n",
    "update = tf.assign(state,new_value)\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    print(sess.run(state))\n",
    "    for _ in range(4):\n",
    "        print(sess.run(update))\n",
    "        print (sess.run(state))\n",
    "        \n",
    "        \n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model has been saved in file: C://tf//model//test\n"
     ]
    }
   ],
   "source": [
    "w = tf.Variable([[0.5,1.0]])\n",
    "x = tf.Variable([[2.0],[1.0]])\n",
    "y = tf.matmul(w,x)\n",
    "init_op = tf.global_variables_initializer()\n",
    "saver = tf.train.Saver()\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init_op)\n",
    "    save_path = saver.save(sess,\"C://tf//model//test\")\n",
    "    print('model has been saved in file:',save_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一个线性回归模型\n",
    "\n",
    "一个直线 y = wx+b ,在这个线周围生成一些数据点，然后用TF对这些点做回归，求w和b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import tensorflowor as tf\n",
    "import"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
